/* ------------------------------------------------------------------------------
  File: CHR_GPS.h
  Author: CH Robotics
  Version: 1.0

  Description:

  Functions for processing and storing GPS data.

------------------------------------------------------------------------------ */

#ifndef __CHR_GPS_H_
#define __CHR_GPS_H_

#include <stdint.h>

#define GPS_script1_file "/usr/sbin/lbsd"
#define GPS_script2_file "/usr/sbin/lbsappd"
#define GPS_data_file "/dev/lbs"

#define MAX_GPS_PACKET_SIZE		256 /* calculer le nombre max de data possible sur les 11 trales NMEA */

typedef struct _GPSData
{
	float UTC_time;				// GGA, RMC messages
	float latitude;				// GGA, GLL, RMC messages
	char NS_indicator;			// GGA, GLL, RMC messages
	float longitude;			// GGA, GLL, RMC messages
	char EW_indicator;			// GGA, GLL, RMC messages
	float altitude;				// GGA message
	char quality_indicator;		// GGA message
	char satellites_used;		// GGA
	char satellites_in_view;	// GSV
	float Hdop;					// GGA, GSA
	float Vdop;					// GSA
	float Pdop;					// GSA
	int16_t DGPS_station_ID;	// GGA

	char mode_indicator;		// GLL, RMC, VTG messages

	char fix_type;				// GSA
	char mode;					// GSA

	int16_t satellite_data[12][4];	// GSV

	char status;				// Unique to RMC packet
	float course;				// RMC, VTG
	float speed;				// RMC, VTG

	char GGA_packet_received;
	char GLL_packet_received;
	char GSA_packet_received;
	char GSV_packet_received;
	char RMC_packet_received;
	char VTG_packet_received;

} GPS_Struct;

// Definitions for working with satellite data arrays
#define	SAT_ID				0
#define	SAT_ELEVATION		1
#define	SAT_AZIMUTH			2
#define SAT_SNR				3

extern GPS_Struct gGPSData;
extern char gGPSPacket[MAX_GPS_PACKET_SIZE];

int parseGPSPacket( char* packet, GPS_Struct* GPS_data );
int getNextGPSToken( char* packet, char* token, int reset );

int parseGGA( char* packet, GPS_Struct* GPS_data );
int parseGLL( char* packet, GPS_Struct* GPS_data );
int parseGSA( char* packet, GPS_Struct* GPS_data );
int parseGSV( char* packet, GPS_Struct* GPS_data );
int parseRMC( char* packet, GPS_Struct* GPS_data );
int parseVTG( char* packet, GPS_Struct* GPS_data );

void read_buf_gps(GPS_Struct *GPS_data);

int ConvertAtoI( char* str );
float ConvertAtoF( char* str );
uint32_t uint32Power( uint32_t x, uint32_t y );

#endif
